package com.xm.servlet.reception_desk.product;

import com.google.gson.Gson;
import com.xm.entity.ShoppingCart;
import com.xm.service.reception_desk.ShoppingCartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 添加购物车
 * @author 康文程
 * @date 2024-1-22 上午 10:56
 */
@WebServlet("/new/shopping/cart")
public class NewShoppingCartServlet extends HttpServlet {
    private final ShoppingCartService shoppingCartService = new ShoppingCartService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String shoppingcartJson = req.getParameter("shoppingCart");
        resp.getWriter().print(shoppingCartService.
                getShoppingCartByCommodityIdAndInformationId(
                        new Gson().fromJson(shoppingcartJson, ShoppingCart.class)));
    }
}
